<?php
$query	=	"SELECT * from comments where `to`=$profile_id and (type=1 or type=0)";

$result = mysql_query($query);
if (mysql_num_rows($result)){ 
	while ($comment = mysql_fetch_assoc($result)) {
	 
		$query        = "SELECT * from users where id='".$comment['from']."'";
		$result_name	= mysql_query($query);
		if (mysql_num_rows($result_name)){ 
/*
			$from = mysql_result ($result_name,0);
			//$f_name = mysql_result ($result_name,0);
			$from = "<a href=\"index.php?do=profile&profile_name=$from\">$from</a>";
*/
			$profile_info=mysql_fetch_array($result_name);
			$from = "<a href=\"index.php?do=profile&profile_id=".$profile_info['id']."\">".$profile_info['name']."</a><br>";
			if (!$RENDER_MOBILE) {
				$from .= GetStatusImg($profile_info['status']);					
			}	

			if ($RENDER_MOBILE) {
				$from .= "<br><img src=\"index.php?do=getphoto&square=1&size=50&id=".$profile_info['photo']."\" title=\"".$profile_info['name']."\">";
			} else {
				$from .= "<br><img src=\"index.php?do=getphoto&square=1&size=75&id=".$profile_info['photo']."\" title=\"".$profile_info['name']."\">";
			}

		} else $from .= $TXT_UNKNOWN;
		
		$time = date("d-m-Y H:i:s",$comment['time']);
		$text = bb2html($comment['text']);
		
		if ( ($id==$comment['to']) or ($id==$comment['from']) ) {
			$delmsg = "<a href=\"index.php?do=pm&delete=".$comment['id']."\">".GetLangString($lang,"txt_delete")."</a>"; 
		} else {
			$delmsg="";
		}
		
		$reply = "<a href='index.php?do=sendpm&to=".$comment['from']."'>".GetLangString($lang,"txt_reply")."</a>";
		if ($RENDER_MOBILE) {
			$COMMENTS = "<tr>
				<td align=\"center\" width=\"75\" valign=\"top\">
				$from<br>$time<br>$reply - $delmsg
				</td>	<td valign=\"top\">$text</td></tr>$COMMENTS";
		} else {
			$COMMENTS = "<tr>
				<td align=\"center\" width=\"125\" valign=\"top\">
				$from<br>$time<br>$reply - $delmsg
				</td>	<td valign=\"top\">$text</td></tr>$COMMENTS";
		}		
	}
	$COMMENTS = "<center><table border=\"1\" width=\"100%\">$COMMENTS</table></center>";
	
	$SITE_MIDDLE .= FormatElement(GetLangString($lang,"txt_comments"),$COMMENTS);
	
	
} else $SITE_MIDDLE .= FormatElement(GetLangString($lang,"txt_comments"),GetLangString($lang,"txt_nocomments"));

//$COMMENTS  = '<div class=label>Send a message</div>';
$COMMENTS = '<form method="POST" ACTION="index.php?do=pm">';
$COMMENTS .= '<textarea name="text" rows="5"></textarea>';
$COMMENTS .= "<input type=\"hidden\" name=\"from\" value=\"$id\">";
$COMMENTS .= "<input type=\"hidden\" name=\"to\" value=\"$profile_id\">";
$COMMENTS .= "Message Type:<select name=\"type\" size=\"2\">
	<option selected value=\"0\">".GetLangString($lang,"txt_comments")."</option>
	<option  value=\"2\">".GetLangString($lang,"txt_pm")."</option>
</select>";
$COMMENTS .= "<input value=\"".GetLangString($lang,"txt_send")."\"	name = \"add\" 	type=\"submit\">" ;
$COMMENTS .= '</form>';
$SITE_MIDDLE .= FormatElement(GetLangString($lang,"txt_send"),$COMMENTS);
			?>
